package com.gnerv.battle.rabbitmq.agent.tool;

import com.google.common.base.CaseFormat;

import java.util.Random;

/**
 * <p>
 * 字符串 工具类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019/5/31
 */
public class StringTools {

    private static final Random RANDOM = new Random();

    private StringTools() {
    }

    /**
     * 转小驼峰
     *
     * @param str
     * @return
     */
    public static String lowerCamel(String str) {
        return CaseFormat.valueOf(str).to(CaseFormat.LOWER_CAMEL, str);
    }

    /**
     * 转大驼峰
     *
     * @param str
     * @return
     */
    public static String upperCamel(String str) {
        return CaseFormat.valueOf(str).to(CaseFormat.UPPER_CAMEL, str);
    }

    /**
     * 随机字符串 小写
     *
     * @param length 字符串长度
     */
    public static String randomString(int length) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int charInt = RANDOM.nextInt(26) + 97;
            stringBuilder.append((char) charInt);
        }
        return stringBuilder.toString();
    }

    /**
     * 去除颜色字符
     *
     * @return
     */
    public static String removeColorCharacters(String str) {
        str = str.replaceAll("\u001B\\[[;\\d]*m", "");
        return str;
    }


}
